package com.situ.edu.controller;

import com.situ.edu.pojo.entity.Auth;
import com.situ.edu.service.IAuthService;
import com.situ.edu.service.impl.AuthServiceImpl;
import com.situ.edu.util.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/auth")
public class AuthController extends BaseController {
    private IAuthService authService = new AuthServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        switch (method){
            case "selectByRole":
                selectByRole(req,resp);
                break;
        }
    }

    private void selectByRole(HttpServletRequest req, HttpServletResponse resp) {
        System.out.println("AuthController.selectByRole");
        String role = req.getParameter("role");
        List<Auth> authList = authService.selectByRole(Integer.parseInt(role));
        toJSON(resp, Result.ok(authList));
    }
}
